package com.mohan.dlxj.service.impl;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.mapper.CircuitMapper;
import com.mohan.dlxj.pojo.Circuit;
import com.mohan.dlxj.service.CircuitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CircuitServiceImpl implements CircuitService {
  @Autowired
  private CircuitMapper circuitMapper;

  @Override
  public JsonResult getCircuitList(long current, long limit) {
    JsonResult jsonResult = new JsonResult();
    jsonResult.setCode(0);
    jsonResult.setMsg("");

    current = limit * (current - 1);
    List<Circuit> list = circuitMapper.selectCircuitPage(current, limit);
    jsonResult.setCount(circuitMapper.selectCircuitAll());//总条数
    jsonResult.setData(list);
    return jsonResult;
  }

  @Override
  public Integer getCircuitAll() {
    Integer all = circuitMapper.selectCircuitAll();
    return all;
  }

  @Override
  public Circuit getCircuitById(Integer id) {
    return circuitMapper.getCircuitById(id);
  }

  @Override
  public void updateCircuit(Circuit circuit) {
    circuitMapper.updateCircuit(circuit);
  }

  @Override
  public void deleteCircuit(Integer id) {
    circuitMapper.deleteCircuit(id);
  }

  @Override
  public void saveCircuit(Circuit circuit) {
    circuitMapper.saveCircuit(circuit);
  }

  @Override
  public void updateStartusing(long id) {
    Circuit circuit = circuitMapper.getCircuitById(id);
    System.out.println(circuit);
    if (circuit.getStartusing_status() == 0) {
      circuit.setStartusing_status(1);
    }else {
      circuit.setStartusing_status(0);
    }
    circuitMapper.updateStartusing(circuit);
  }
}
